package com.pt.demo;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.hardware.display.DisplayManager;
import android.os.IBinder;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;

/**
 * Created by Winner on 2017/12/7.
 */

public class HomeService extends Service {

    // 获取设备上的屏幕
    DisplayManager mDisplayManager;// 屏幕管理器
    Display[] displays;// 屏幕数组
    DemoPresentation mPresentation;

    @Override
    public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
        return null;
    }

    @SuppressLint("NewApi")
    @Override
    public void onCreate() {
// TODO Auto-generated method stub
        super.onCreate();
//registerHomeandMenuActionReceiver();// 注册监听home键和菜单键的监听广播
// 双屏异显
        mDisplayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
        displays = mDisplayManager.getDisplays();
        showView();

    }

    @SuppressLint("NewApi")
    private void showView() {
        if (null == mPresentation) {
            mPresentation = new DemoPresentation(getApplicationContext(), displays[1], new PresentationContents(getNextPhoto()));// displays[1]是副屏
            mPresentation.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            mPresentation.show();

            Toast.makeText(getApplicationContext(), "哈哈哈哈哈", Toast.LENGTH_LONG).show();
        }
    }

    // 定义存储photo的数组
    private int[] photos = new int[]{R.drawable.guild1, R.drawable.guild2,
            R.drawable.guild3, R.drawable.ic_launcher_background, R.drawable.puzzle,
            R.drawable.test};
    // 记录下一张照片的Id
    private int nextPhotoNumber = 0;

    private int getNextPhoto() {
        int nextPhoto = photos[nextPhotoNumber];
        nextPhotoNumber = (nextPhotoNumber + 1) % photos.length;
        return nextPhoto;
    }
}
